package com.liu.sms.config;

import com.liu.shop.common.constant.RabbitConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    // 设置想要监听的交换机
    @Bean
    public TopicExchange informExchange(){
        return new TopicExchange(RabbitConstant.INFORM_EXCHANGE,true,false);
    }

    // 设置发送短信的队列
    @Bean
    public Queue smsQueue(){
        return new Queue(RabbitConstant.SMS_QUEUE,true,false,false);
    }

    // 设置发送邮箱的队列
    @Bean
    public Queue emailQueue(){
        return new Queue(RabbitConstant.EMAIL_QUEUE,true,false,false);
    }

    // 绑定发送短信的队列，交换机，路由规则
    @Bean
    public Binding bindingSmsQueue(){
        return BindingBuilder.bind(smsQueue()).to(informExchange()).with(RabbitConstant.SMS_RULER);
    }

    // 绑定发送邮箱的队列，交换机，路由规则
    @Bean
    public Binding bindingEmailQueue(){
        return BindingBuilder.bind(emailQueue()).to(informExchange()).with(RabbitConstant.EMAIL_RULER);
    }
}
